﻿using LeaRun.Application.Entity.AppManage;
using LeaRun.Application.IService.AppManage;
using LeaRun.Data.Repository;
using System.Collections.Generic;

namespace LeaRun.Application.Service.AppManage
{
    /// <summary>
    /// App 模板服务
    /// </summary>
    public class App_TemplatesService : RepositoryFactory, App_TemplatesIService
    {
        /// <summary>
        /// 获取对象
        /// </summary>
        /// <param name="keyValue">关键字</param>
        /// <returns></returns>
        public App_TemplatesEntity GetEntity(string keyValue)
        {
            return base.BaseRepository().FindEntity<App_TemplatesEntity>(keyValue);
        }
        /// <summary>
        /// 获取列表
        /// </summary>
        /// <param name="queryJson"></param>
        /// <returns></returns>
        public IEnumerable<App_TemplatesEntity> GetList(string queryJson)
        {
            return base.BaseRepository().FindList<App_TemplatesEntity>("select * from App_Templates where F_ProjectId='" + queryJson + "'");
        }
        /// <summary>
        /// 删除模板
        /// </summary>
        /// <param name="keyValue"></param>
        public void RemoveForm(string keyValue)
        {
            base.BaseRepository().ExecuteBySql("delete from App_Templates where F_ProjectId='" + keyValue + "'");
        }
        /// <summary>
        /// 保存模板
        /// </summary>
        /// <param name="keyValue"></param>
        /// <param name="entity"></param>
        public void SaveForm(string keyValue, App_TemplatesEntity entity)
        {
            if (!string.IsNullOrEmpty(keyValue))
            {
                entity.Modify(keyValue);
                base.BaseRepository().Update<App_TemplatesEntity>(entity);
                return;
            }
            entity.Create();
            base.BaseRepository().Insert<App_TemplatesEntity>(entity);
        }
    }
}
